//token验证模块
const jwt = require('jsonwebtoken')

//创建一个类 
class JWT{
    //里面有一个构造函数
constructor(token){
    this.token = token
}
    //生成token的函数
generateToken(){
let data = this.token
let email = '905888137@qq.com'
let time = Math.floor(new Date()/1000)
let token = jwt.sign({
    data,
    //设置30分钟过期
    exp:time+60*30
},email)
return token
}
    //验证token的函数
verifyToken(){
    let token = this.token
    let email = '905888137@qq.com'
    let res = null
    try{
        res= jwt.verify(token,email)|| {}
            console.log(res)
        }catch(e){
        res = "err"
    }
    return res
}
}

exports.JWT = JWT